package api

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"go-admin-server/app/dto/response"
	"go-admin-server/app/service"
	"go-admin-server/common/ginx"
	"strings"
)

type operateLogApi struct{}

func NewOperateLogHttp(group *gin.RouterGroup) {
	s := &operateLogApi{}
	group.GET("/operateLog", s.List)
	group.POST("/operateLog", s.Create)
	group.DELETE("/operateLog", s.Delete)
	group.PUT("/operateLog", s.Update)
}

func (s operateLogApi) List(ctx *gin.Context) {
	page := ginx.QueryInt(ctx, "page", 1)
	size := ginx.QueryInt(ctx, "size", 10)
	list, count := service.OperateLogService.List(page, size)
	response.SuccessPage(ctx, page, size, int(count), &list)
}

func (s operateLogApi) Create(ctx *gin.Context) {
	ip := strings.Split(ctx.Request.RemoteAddr, ":")[0]
	fmt.Println(ip)
	logId, err := service.OperateLogService.Create("导出预警", "导出预警", "导出预警", ip)
	if err != nil {
		response.Fail(ctx, 400, err.Error())
	} else {
		response.Success(ctx, logId)
	}
}

func (s operateLogApi) Delete(ctx *gin.Context) {

}

func (s operateLogApi) Update(ctx *gin.Context) {

}
